<?php
/**
* @copyright (C) 2003 - 2004 SystN International Pty Ltd.
* @license http://www.SystN.com
* SystN is Free Software
*/

Class Dirver{
	//连接数据库
	function DBLink($dba=''){
		$this->LinkID = ($dba['pconnect'] == 1)? @mysql_pconnect($dba['dbhost'], $dba['dbuser'], $dba['dbpass']) : @mysql_connect($dba['dbhost'], $dba['dbuser'], $dba['dbpass']) or die("Connect to MySQL (".$dba['dbhost'].",".$dba['dbuser'].") failed");
		//选择连接数据库
		@mysql_select_db($dba['dbname'], $this->LinkID) or die('Cannot use database '.$dba['dbname']);
		if($this->version() > '4.1') {
			//字符集
			$charset = (in_array(strtolower($dba['charset']), array('gbk', 'big5', 'utf-8')))?$dba['charset']:'utf-8';
			//ATTENTION: remove the following line if you want to use the default database character set.
			$this->query("SET NAMES '".str_replace('-', '', $dba['charset'])."'");
		}
		return $this->LinkID;
	}
	
	//查询语句
	function query($query,$limit='') {
		$this -> nums ++;
		//检测如果有限制数据集则处理
		if($limit>0){
			$query = $query.' LIMIT '.$limit;
		}
		$this-> Lists .= $query.'<br>';
		return mysql_query($query,$this->LinkID);
	}
	
	//返回数组资料
	function fetch_array($query) {
		return @mysql_fetch_array($query, MYSQL_ASSOC);
	}
	
	//取得返回列的数目
	function num_rows($query){
		return @mysql_num_rows($query);
	}
	
	//返回单列的各字段
	function fetch_row($query) {
		return @mysql_fetch_row($query);
	}
	
	//返回最后一次使用 INSERT 指令的 ID
	function insert_id(){
		return @mysql_insert_id($this->LinkID);
	}
	
	//关闭当前数据库连接
	function close(){
		return @mysql_close($this->LinkID);
	}
	
	//检测mysql版本
	function version(){
		$query = @mysql_query("SELECT VERSION()",$this->LinkID);
		return	@mysql_result($query, 0);
	}
	
	//查询语句数
	function sql_num(){
		return $this -> nums;
	}
	
	//查询语句列表
	function sql_debug(){
		return $this-> Lists;
	}
	
	
}
?>